<?php
/**
*  会员课程协议
*/
namespace app\api\model;
use think\Model;

class MemberCourseAgreement extends Model
{
    /**
    *  列表
    */
    public function _list($where = '', $order_by="sort asc", $page_size = PAGE_SIZE_API){
        $data = $this->alias('mca')->where($where)
            ->field("mca.*, cc.title, cc.image")
            ->join("class_course cc", 'cc.id=mca.cid', 'LEFT')
            ->order($order_by)
            ->paginate($page_size)
            ->toArray();
        return $data;
    }
    
    /**
    * 签署协议
    * @param mid int 会员id
    * @param id int 协议id
    */
    public function _signAgreement($mid, $id){
        $update = [
            'is_sign_agreement' => 1,
            'sign_time' => time(),
        ];
        $ret = $this->where([['mid', '=', $mid], ['id', '=', $id], ['is_sign_agreement', '=', '-1']])->update($update);
        if(!$ret){
            $this->error = '协议签署失败';
            return false;
        }
        return true;
    }
    
    
    /**
    * 通过id获取信息
    */
    public function _getInfoByID($id){
        return $this->alias('mca')
            ->field("mca.*, cc.title, cc.image")
            ->join("class_course cc", 'cc.id=mca.cid', 'LEFT')
            ->where([['mca.id', '=',$id]])->find();
    }
    
    /**
    * 通过条件获取信息
    */
    public function _getInfoByWhere($where){
        return $this->where($where)->find();
    }


}